const app = getApp();
const common = require('../../../utils/common.js');
const api = require('../../../config/api.js');

Page({
  data: {
    imgUrl: app.globalData.imgurl,
    addressList: [],
  },
  onShow: function () {
    this.getAddressList();
  },
  getAddressList (){
    let that = this;
    common.request(api.AddressList, {}, 'GET').then(function (data) {
      if (data.type === 'success') {
        that.setData({
					addressList: data.data.regionList
        });
      }
    });
  },
	addressEdit(event) {
    let addressId = event.currentTarget.dataset.address.id;
    wx.navigateTo({
			url: '/pages/ucenter/addressEdit/addressEdit?addressId=' + addressId
		})
  },
  addressAdd(event) {
    console.log(event)
    wx.navigateTo({
      url: '/pages/ucenter/selfRaising/add'
    })
  },
  deleteAddress(event){
    let that = this;
    wx.showModal({
      title: '',
      content: '确定要删除地址？',
      success: function (res) {
        if (res.confirm) {
          let addressId = event.target.dataset.addressId;
					common.request(api.AddressDelete, { id: addressId }, 'POST').then(function (data) {
            if (data.type === 'success') {
							common.showSuccessToast(data.content);
              setTimeout(function () {
                that.getAddressList();
              }, 1500)
            }
          });
        }
      }
    })
    return false;
  }
})